package com.hospital.controller;

import com.hospital.domain.DTO.DepDTO;
import com.hospital.domain.pojo.Department;
import com.hospital.domain.utils.Result;
import com.hospital.service.DepService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/department")
@Tag(name = "科室接口", description = "无")
public class DepController {
    private final DepService depService;

    @GetMapping("/query")
    @Operation(summary = "查看科室")
    public Result queryDep(){
        return depService.queryDep();
    }

    @GetMapping("/Info/{DepId}")
    @Operation(summary = "查看科室信息")
    public Result getDep(@PathVariable("DepId") Integer DepId){
        Department info = depService.lambdaQuery().eq(Department::getDepId, DepId).one();
        return Result.ok(info);
    }

    @DeleteMapping("/delete/{DepId}")
    @Operation(summary = "删除科室")
    public Result removeDep(@PathVariable("DepId") Integer DepId){
        return depService.removeDep(DepId);
    }

    @PostMapping("/add")
    @Operation(summary = "新增科室")
    public Result addDep(@RequestBody DepDTO depDTO){
        return depService.addDep(depDTO.getName(), depDTO.getInfo(), depDTO.getLevel(), depDTO.getPhone());
    }

    @PutMapping("/update")
    @Operation(summary = "编辑科室")
    public Result updateDep(@RequestBody DepDTO depDTO){
        return depService.updateDep(depDTO.getDepId(), depDTO.getName(), depDTO.getInfo(), depDTO.getLevel(), depDTO.getPhone());
    }
}
